import axios from 'axios'
// axios.defaults.baseURL = 'http://bgsentiment.com:8080'

// export const Login = (params) => {
//   return axios.post('/login', params).then(res => res)
// }
const protocolStr = document.location.protocol
let protocol = 'http'
if (protocolStr === 'http:') {
  protocol = 'http://dy.6soft.com'
} else {
  protocol = 'https://dy.6soft.com'
}

const isPro = Object.is(process.env.NODE_ENV, 'production')

axios.defaults.baseURL = isPro ? protocol : protocol

axios.interceptors.request.use(
  config => {
    let mytoken = localStorage.getItem('userToken') || ''
    // if (mytoken) {
    //   config.headers['token'] = mytoken
    // }
    // console.log(config)
    // if(config.method == 'post') {
    //   config.data = {
    //     token: mytoken,
    //     ...config.data
    //   }
    //   console.log(config)
    // } else 
    if(config.method == 'get') {
      if(config.url.indexOf('login') > 0) {

      } else {
        config.params = {
          token: mytoken,
          ...config.params
        }
      }
      
    }
    
    return config
  },
  err => {
    return Promise.reject(err)
  })

export const getLoginPic = obj => {
  return axios.get('/login', {params: obj}).then(res => res.data)
}
// ckj 登录
export const checkLogin = params => axios.post('user/login', params).then(res => res.data)

// ckj 获取首页进行中任务
export const getGoaheadTask = () => {
  return axios.get('/task/running').then(res => res.data)
}
// ckj 获取已完成的任务
export const getFinishTask = obj => {
  return axios.get('/task/finish', {params: obj}).then(res => res.data)
}
// ckj 获取最近的任务
export const getRecentTask = () => {
  return axios.get('/task/recent').then(res => res.data)
}
// ckj 用pageNum,pageSize获取任务列表及模糊搜索
export const getSearchList = obj => {
  // console.log(obj)
  return axios.get('/task/list', {params: obj}).then(res => res.data)
}
// 用pageNum,pageSize获取已完成任务列表
export const getFinishList = obj => {
  return axios.get('/task/finish', {params: obj} ).then(res => res.data)
}
// ckj 利用id获取任务详情
export const getTaskDetail = id => {
  return axios.get("/task/"+id).then(res => res.data)
}
// ckj 添加任务
export const addNegative = obj => {
  return axios.get('/task/insert', {params: obj} ).then(res => res.data)
}
// ckj 用pageNum,pageSize获取关键字列表以及模糊搜索
export const getKeywordsList = obj => {
  return axios.get('/keywords/list', {params: obj}).then(res => res.data)
}
// ckj 获取模板列表
export const getTemplateList = obj => {
  return axios.get('/template/list', {params: obj}).then(res => res.data)
}
// ckj 用的id获取模板详细信息
export const getTempltateUpdateList = id => {
  return axios.get("/template/"+id).then(res => res.data) 
}
// ckj 更新模板
export const UpdataTemplate = obj => {
  return axios.get('/template/update', {params: obj}).then(res => res.data)
}
// 删除模板接口  /template/delete
export const deleteTemplate = obj => {
  return axios.get('/template/delete', {params: obj}).then(res => res.data)
}
// 用负面舆情创建任务时获取用户的负面舆情模块详细信息
export const getModuleInsert1 = () => {
  return axios.get('/module/insert1').then(res=>res.data)
}
// 用五大模块创建任务时获取用户的五大模块详细信息
export const getModuleInsert2 = () => {
  return axios.get('/module/insert2').then(res=>res.data)
}
// 获取特定任务的结果列表 
export const getResultList = obj => {
  return axios.get('/result/list', {params: obj}).then(res=>res.data)
}
// ckj 获取行业信息
export const getList = () => {
  return axios.get('/list').then(res=>res.data)
}
// getTaskInser
export const getTaskInser = obj => {
  return axios.get('/task/insertfive', {params: obj}).then(res=>res.data)
}
// 用id获取模块详细信息
export const getModule = obj => {
  return axios.get("/module/"+obj.id+"?pageNum="+obj.pageNum+"&templateName="+obj.templateName).then(res => res.data)
}
// ckj 上传负面舆情的文件
export const teskFiles = (formData) => {
  // console.log(formData)
  return axios.post('/task/insert/batch1', formData).then(res => res.data )
}
// ckj 上传五大模块的文件
export const teskFiveFiles = formData => {
  return axios.post('/task/insert/batch2', formData).then(res => res.data)
}
// ckj 更换模块的默认模板  module/updatedt?mid=1&tid=1
export const ChangeUpdateModule = obj => {
  return axios.get('module/updatedt', {params: obj}).then(res=>res.data)
}
// ckj 更改舆情模块设置
export const changeModule = obj => {
  return axios.get('module/update1', {params: obj}).then(res=>res.data)
}
// ckj 获取所有模板
export const getAllTemplate = () => {
  return axios.get('/template/getAll').then(res=>res.data)
}
// ckj 添加关键字 
export const addKeywords = obj => {
  return axios.get('/keywords/insert', {params: obj}).then(res=>res.data)
}
// ckj 删除关键字
export const deleteKeywords= obj => {
  return axios.get('/keywords/delete', {params: obj}).then(res => res.data)
}
// /keywords/update/{id} 更新的时候用id获取所有模板
export const getUpdateKeywords = id => {
  return axios.get("/keywords/update/"+id).then(res => res.data) 
}
// /keywords/update/  更新关键字
export const UpdateKeywordsList = obj => {
  return axios.get("/keywords/update", {params: obj}).then(res => res.data) 
}
// changeModule2
export const changeModule2 = obj => {
  return axios.get('module/update2', {params: obj}).then(res=>res.data)
}
// fiveModule/list  获取用户的五大模块设置
export const getFiveModuleList = () => {
  return axios.get('/fiveModule/list').then(res=>res.data)
}
// /template/insert    添加模板
export const addTemplateInsert = obj => {
  return axios.get("/template/insert", {params: obj}).then(res => res.data) 
}